#include "IO.hh"
void IO::showMainMenu() {
    std::cout << "\nChoose your action:\n";
    std::cout << "1. Move to another room\n";
    std::cout << "2. View Player Status\n";
    std::cout << "3. End Turn (Restore AP, but -10 MaxHP)\n";
    std::cout << "4. Exit Game\n";
    std::cout<<"Enter your choice: ";
}

int IO::getNumber(){
    int number;
    bool valid=false;
    string input;
    while (!valid) {
        getline(cin,input);
        if(input.empty()){
            std::cout << "Invalid input. Try again: ";
            continue;
        }
        valid=true;
        for(char i : input){
            //如果input不是数字字符（0-9）
            if (!std::isdigit(i)) {  
                std::cout << "Invalid input. Try again: ";
                valid=false;
                break;
            }
        }
    }
    number=stoi(input);//string to integer
    return number;
}

void IO::showIntroduction(){
    std::cout << "Welcome to the Tower of Invention.\n";
    std::cout << "Your journey begins...\n";
    std::cout << "[You may reset AP up to 3 times per run. Each reset reduces your Max HP by 10.]\n";
}

void IO::showEscapeEnd(){
    std::cout << "\n[Escape Ending Reached!]\n";
    std::cout << "\nCongratulations! You have successfully won!\n";
    std::cout << "The journey was tough, but you found a way out.\n";
}

void IO::showFightChoice(){
    std::cout << "\n--- Your Turn ---\n";
    std::cout << "1. Attack\n2. Use Item\n3. Check Status\n4. Run Away[-2 AP]\n";
    std::cout << "Choose your action: ";
}

void IO::showMoveChoice(){
    std::cout << "1. Move Forward\n2. Move Backward\n";
    std::cout<<"Enter your choice: ";
}

void IO::endTurn(int apResetUsed,int maxApReset){
    std::cout << "[Ending Turn... AP Restored.]\n";
    std::cout << "[AP Reset used (" << apResetUsed << "/" << maxApReset << "). AP restored.]\n";
    std::cout << "[Max HP reduced by 10 as a cost for AP reset.]\n";
}

string IO::getString(){
    bool valid=false;
    string input;
    while (!valid) {
        getline(cin,input);
        if(input.empty()){
            std::cout << "Invalid input. Try again: ";
            continue;
        }
        valid=true;
    }
    return input;
}

void IO::showRestRoomMenu(){
    std::cout << "\nYou can:\n";
    std::cout << "1. Check [status]\n";
    std::cout << "2. Enter [code]\n";
    std::cout << "3. [leave] this room\n";
    std::cout << "What do you want to do? ->";
}